#!/usr/bin/make -f
_KaiwudbSourceDir=${GOPATH}/src/gitee.com/kwbasedb
build_dir=$(shell if [ ! -d $(_KaiwudbSourceDir)/build ]; then echo "noexist"; else echo "exist";  fi)
%:
	dh $@

override_dh_auto_configure:

build-stamp:
# whether the build directory is exists, if not, building kwbase
ifeq ("$(build_dir)", "noexist")
	cd ../../ && bash .CI/4_build_kwbase.sh 
else
	echo "KaiwuDB build is existed."
endif
override_dh_auto_build-arch: build-stamp
override_dh_auto_build-indep: build-stamp

override_dh_clean:

override_dh_usrlocal:

install-stamp:
	mkdir -p debian/kaiwudb-server/usr/local/kaiwudb/bin
	mkdir -p debian/kaiwudb-server/usr/local/kaiwudb/lib
	mkdir -p debian/kaiwudb-libcommon/usr/local/kaiwudb/lib
	mkdir -p debian/kaiwudb-libcommon/usr/share/doc/kaiwudb
#kaiwudb-libcommon
	install -m 755 ../../NOTICE.txt debian/kaiwudb-libcommon/usr/share/doc/kaiwudb
	install -m 755 ../../install/lib/libcommon.so debian/kaiwudb-libcommon/usr/local/kaiwudb/lib
#kaiwudb-server
	install -m 755 ../../install/bin/kwbase debian/kaiwudb-server/usr/local/kaiwudb/bin
	install -m 755  ../../install/lib/libkwdbts2.so debian/kaiwudb-server/usr/local/kaiwudb/lib

# do not stirp debuginfo and symbol tables
override_dh_strip:
	dh_strip -Xlibcommon.so -Xlibkwdbts2.so -Xkwbase
override_dh_install-arch: install-stamp

override_dh_install-indep: install-stamp

override_dh_shlibdeps:
	dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info